home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.4)
-
- '''Test suite for the profile module.'''
- import profile
- import os
- from test.test_support import TESTFN, vereq
- ticks = 0
-
- def test_1():
- global ticks
- ticks = 0
- prof = profile.Profile(timer)
- prof.runctx('testfunc()', globals(), globals())
- prof.print_stats()
-
-
- def timer():
- return ticks * 0.001
-
-
- def testfunc():
- global ticks, ticks
- ticks += 199
- helper()
- helper()
- ticks += 201
-
-
- def helper():
- global ticks, ticks, ticks, ticks, ticks, ticks, ticks
- ticks += 1
- helper1()
- ticks += 3
- helper1()
- ticks += 6
- helper2()
- ticks += 5
- helper2()
- ticks += 4
- helper2()
- ticks += 7
- helper2()
- ticks += 14
-
-
- def helper1():
- global ticks, ticks
- ticks += 10
- hasattr(C(), 'foo')
- ticks += 19
-
-
- def helper2():
- global ticks, ticks, ticks
- ticks += 11
- hasattr(C(), 'bar')
- ticks += 13
- subhelper()
- ticks += 15
-
-
- def subhelper():
- global ticks, ticks
- ticks += 2
- for i in range(2):
-
- try:
- C().foo
- continue
- except AttributeError:
- ticks += 3
- continue
-
-
-
-
-
- class C:
-
- def __getattr__(self, name):
- global ticks
- ticks += 1
- raise AttributeError
-
-
-
- def test_2():
- d = globals().copy()
-
- def testfunc():
- global x
- x = 1
-
- d['testfunc'] = testfunc
- profile.runctx('testfunc()', d, d, TESTFN)
- vereq(x, 1)
- os.unlink(TESTFN)
-
-
- def test_3():
- result = []
-
- def testfunc1():
-
- try:
- len(None)
- except:
- pass
-
-
- try:
- len(None)
- except:
- pass
-
- result.append(True)
-
-
- def testfunc2():
- testfunc1()
- testfunc1()
-
- profile.runctx('testfunc2()', locals(), locals(), TESTFN)
- vereq(result, [
- True,
- True])
- os.unlink(TESTFN)
-
-
- def test_main():
- test_1()
- test_2()
- test_3()
-
- if __name__ == '__main__':
- test_main()
-
-